<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <h:head>
        <title>#{bundle.marketing}</title>
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
        <ui:composition>
        <h:form >
            <script type="text/javascript">  
                function handleSaveRequestMarketing(xhr, status, args) {  
                    if(args.validationFailed || !args.success) {  
                        jQuery('#dialog').effect("shake", { times:3 }, 100);  
                    } else {  
                        dlgMarketing.hide();  
                    }  
                }
                
                function handleDeleteRequestMarketing(xhr, status, args) {  
                    if(args.validationFailed || !args.success) {  
                        jQuery('#dialog').effect("shake", { times:3 }, 100);  
                    } else {  
                        dlgDelMarketings.hide();  
                    }  
                }
                
                function componenKeyPress(e, id) {
                    var code = (e.keyCode ? e.keyCode : e.which);
                    if(code==13) {
                        if (id == 'marketingNo1') document.getElementById('marketingName1').focus();
                        else submitMarketing.jq.click();
                        
                        e.preventDefault ? e.preventDefault() : e.returnValue = false;
                        e.stopPropagation();
                    }
                }
                
            </script>  

            <p:toolbar>
                <p:toolbarGroup align="left">
                    <p:commandButton value="#{bundle.btnNew}"
                                     icon="ui-icon-document" rendered="#{menuBean.cekButtonAccess(366,'INS;')}"
                                     action="#{marketingBean.newData()}"  
                                     oncomplete="dlgMarketing.show()"
                                     process="@this" update=":#{utilityBean.findClientId('displayMarketing')}"> 
                        <pe:resetEditableValues for="displayMarketing"/>
                    </p:commandButton>

                    <p:commandButton value="#{bundle.btnOpen}" oncomplete="dlgMarketing.show()" 
									rendered="#{menuBean.cekButtonAccess(366,'OPN;')}"
                                     icon="ui-icon-disk" actionListener="#{marketingBean.openData()}"
                                     update=":#{utilityBean.findClientId('displayMarketing')}" > 
                    </p:commandButton>

                    <p:commandButton type="button" value="#{bundle.btnDelete}" icon="ui-icon-trash"
                                     onclick="dlgDelMarketings.show()"  rendered="#{menuBean.cekButtonAccess(366,'DEL;')}" />

                    <!--p:commandButton type="push" value="#{bundle.btnPrint}" icon="ui-icon-print"/ -->
                </p:toolbarGroup>
            </p:toolbar>
            <br />
            <p:dataTable id="dtMarketings" var="marketing" value="#{marketingBean.marketings}"
                         resizableColumns="true" rowIndexVar="noUrut"  selection="#{marketingBean.selectedData}" selectionMode="single" 
                         rowKey="#{marketing.marketingId}" >
                <p:column style="width: 10px">
                    <f:facet name="header">No.</f:facet>
                    <h:outputText value="#{noUrut+1}" />
                </p:column>               
                <p:column style="width:200px">
                    <f:facet name="header">#{bundle.globalName}</f:facet>
                    <h:outputText value="#{marketing.marketingName}" />
                </p:column>
                 <p:column style="width:100px">
                     <f:facet name="header">#{bundle.branch}</f:facet>
                    <h:outputText value="#{usersBean.selectItemValueOf(usersBean.avaibleBranch,marketing.branchId)}" />
                </p:column>
                
            </p:dataTable>
            
            <p:confirmDialog message="#{bundle.confirmDelete}" appendToBody="true" 
                             header="#{bundle.confirmDeleteHeader}" severity="alert" widgetVar="dlgDelMarketings">
                <h:panelGrid cellspacing="0" cellpadding="0" styleClass="pComBtnD">
                    <f:facet name="footer">
                        <p:commandButton value="#{bundle.btnYes}" update="dtMarketings" process="@this" 
                                         oncomplete="handleDeleteRequestMarketing(xhr, status, args)"  
                                         actionListener="#{marketingBean.delete()}" />  
                        <p:commandButton value="#{bundle.btnCancel}" onclick="dlgDelMarketings.hide()" type="button" />  
                    </f:facet>
                </h:panelGrid>  
            </p:confirmDialog> 
        </h:form>
            <p:dialog header="#{bundle.marketing}" widgetVar="dlgMarketing" closable="true" modal="true" appendToBody="true">
                <p:ajax immediate="true" event="close" listener="#{marketingBean.handleClose}"/>
                <h:form>
                <h:panelGrid id="displayMarketing" columns="3" styleClass="addELIT">
                                        
                    <h:outputLabel styleClass="addL" value= "#{bundle.globalName}" /><h:outputLabel value= ":" />
                    <p:inputText value="#{marketingBean.unsaveData.marketingName}" onkeyup="upperCase(this)"
                                 label="#{bundle.globalName}" style="width: 150px;"
                                 required="#{marketingBean.unsaveData!=null}"  >
                       
                    </p:inputText>  
                    
                     <h:outputLabel value= "#{bundle.branch}" /><h:outputLabel value= ":" />
                    <h:panelGroup>
                        
                        <p:selectOneMenu value="#{marketingBean.unsaveData.branchId}" style="width: 170px" rendered="#{marketingBean.unsaveData!=null}"
                                         required="true" requiredMessage="#{bundle.branch} #{bundle.requiredInput}" >
                            <f:selectItem itemLabel="#{bundle.Select} #{bundle.branch}" itemValue="" />
                            <f:selectItems value="#{usersBean.avaibleBranch}" />
                        </p:selectOneMenu>
                    </h:panelGroup>
                </h:panelGrid>

                <h:panelGrid cellpadding="0" styleClass="pComBtnSTDR">
                    <f:facet name="footer">  
                        <p:commandButton value="#{bundle.btnSave}" icon="ui-icon-disk" actionListener="#{marketingBean.trySave()}"  rendered="#{menuBean.cekButtonAccess(362,'UPD;')}"
                                         update=":#{utilityBean.findClientId('dtMarketings')}" widgetVar="submitMarketing"                 
                                         oncomplete="handleSaveRequestMarketing(xhr, status, args)"/>  
                        <p:commandButton value="#{bundle.btnClose}" icon="ui-icon-document" immediate="true"
                                         oncomplete="dlgMarketing.hide()" update="displayMarketing" process="@this">
                            <pe:resetEditableValues for="displayMarketing"/>  
                        </p:commandButton>
                            
                    </f:facet>
                </h:panelGrid>
                    </h:form>
            </p:dialog>
        
        </ui:composition>
    </h:body>
</html>